package mx.service.impl;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import mx.entity.Position;
import mx.entity.Science;
import mx.entity.Station;
import mx.entity.TicketType;
import mx.service.PositionService;
import mx.service.ScienceService;
import mx.service.StationService;
import mx.service.TicketTypeService;

@Component
public class InitComponent implements ServletContextListener,
		ApplicationContextAware {

	private static ApplicationContext applicationContext;

	public void contextInitialized(ServletContextEvent sce) {
		ServletContext application = sce.getServletContext();

		TicketTypeService ticketTypeService = (TicketTypeService) applicationContext
				.getBean("ticketTypeService");
		List<TicketType> ticketTypeTist = ticketTypeService.list();
		application.setAttribute("ticketTypeList", ticketTypeTist);// 获取票类型

		ScienceService scienceService = (ScienceService) applicationContext
				.getBean("scienceService");
		List<Science> scienceList = scienceService.list(null);
		application.setAttribute("scienceList", scienceList);// 获取景区名

		StationService stationService = (StationService) applicationContext
				.getBean("stationService");
		List<Station> stationList = stationService.list(null);
		application.setAttribute("stationList", stationList);// 获取岗位名

		PositionService positionService = (PositionService) applicationContext
				.getBean("positionService");
		List<Position> positionList = positionService.list(null);
		application.setAttribute("positionList", positionList);// 获取职位名
	}

	public void contextDestroyed(ServletContextEvent sce) {

	}

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		InitComponent.applicationContext = applicationContext;
	}

}
